// /abc/.test('')

function test(string) {
  let i
  let startIndex, endIndex
  function waitForA(char) {
    if (char === 'a') {
      startIndex = i
      return waitForB
    }
    return waitForA
  }
  function waitForB(char) {
    if (char === 'b') {
      return waitForC
    }
    return waitForB
  }
  function waitForC(char) {
    if (char === 'c') {
      endIndex = i
      return end
    }
    return waitForC
  }

  function end() {
    return end
  }

  let currentState = waitForA

  for(i = 0; i < string.length; i++) {
    let nextState = currentState(string[i])
    currentState = nextState

    if (currentState === end) {
      console.log(startIndex, endIndex);

      // currentState = 
      return true
    }
  }

  return false
}

console.log(test('dabcfdsf'));